﻿namespace ClassyBlog.ExtensionMethods.Specs.Unit
{
    using System;
    using System.Collections.Generic;

    using Machine.Specifications;

    [Subject(typeof(CollectionExtensions))]
    public class when_trying_to_add_all_for_a_null_collection
    {
        static ICollection<string> collection;
        static Exception exception;

        Establish context = () => collection = null;

        Because of = () => exception =
            Catch.Exception(() =>
                collection.AddAll(new[]
                                      {
                                          "foo",
                                          "bar",
                                          "baz"
                                      }));

        It should_throw_exception = () =>
            exception.ShouldBeOfType<ArgumentNullException>();
    }

    [Subject(typeof(CollectionExtensions))]
    public class when_trying_to_add_all_with_null_to_collection
    {
        static ICollection<string> collection;
        static Exception exception;

        Establish context = () => collection = new List<string>();

        Because of = () => exception =
            Catch.Exception(() => collection.AddAll(null));

        It should_throw_exception = () =>
            exception.ShouldBeOfType<ArgumentNullException>();
    }

    [Subject(typeof(CollectionExtensions))]
    public class when_add_all_to_collection
    {
        static ICollection<string> collection;

        Establish context = () => collection = new List<string>();

        Because of = () => collection.AddAll(new[]
                                                 {
                                                     "foo",
                                                     "bar",
                                                     "baz"
                                                 });

        It should_add = () =>
        {
            collection.ShouldContain("foo");
            collection.ShouldContain("bar");
            collection.ShouldContain("baz");
        };
    }
}